@extends("layout.main")
@section("content")

<div class="layui-container fly-marginTop fly-user-main">
    <ul class="layui-nav layui-nav-tree layui-inline" lay-filter="user">
        <li class="layui-nav-item">
            <a href="/user/{{\Auth::id()}}">
                <i class="layui-icon">&#xe609;</i>我的主页</a></li>
        <li class="layui-nav-item  ">
            <a href="/user/myquestion">
                <i class="layui-icon">&#xe612;</i>用户中心</a></li>
        <li class="layui-nav-item ">
            <a href="{{url('/user/set')}}">
                <i class="layui-icon">&#xe620;</i>基本设置</a></li>
        <li class="layui-nav-item  layui-this">
            <a href="/user/msg/{{\Auth::id()}}">
                <i class="layui-icon">&#xe611;</i>我的消息</a></li>
        <li class="layui-nav-item ">
            <a href="/auth/get/">
                <i class="layui-icon">&#xe61e;</i>产品授权</a></li>
    </ul>
    <div class="site-tree-mobile layui-hide">
        <i class="layui-icon">&#xe602;</i></div>
    <div class="site-mobile-shade"></div>
    <div class="fly-panel fly-panel-user" pad20>
        <div class="layui-tab layui-tab-brief" lay-filter="user" id="LAY_msg" style="margin-top: 15px;">
            <button class="layui-btn layui-btn-danger " id="LAY_delallmsg">清空全部消息</button>
            <div id="LAY_minemsg" style="margin-top: 10px;">
                <ul class="mine-msg">

                    @foreach($msgs as $msg)
                    <li data-id="85636">
                        <blockquote class="layui-elem-quote">您在
                            <a target="_blank" href="/question/{{$msg->question->id}}/show">
                                <cite>{{$msg->question->title}}</cite>
                            </a>中，被{{$msg->byUser->name}}</a>{{$msg->operate}}
                            </blockquote>
                        <p>
                                <span>{{$msg->created_at->diffForHumans()}}</span>

                                <a  mid = "{{$msg->id}}"  href="javascript:;" class="layui-btn layui-btn-sm layui-btn-danger fly-delete clearOne">

                                    删除

                                </a>

                            </p>
                    </li>

                    @endforeach
                        <div id="pull_right">
                            <div class="pull-right">
                                {{$msgs->links()}}
                            </div>
                        </div>
                </ul>
            </div>
        </div>
    </div>
</div>

<script>
    layui.use(['jquery','layer'], function() {
        var $ = layui.jquery;
        var layer = layui.layer;
        $('.clearOne').click(function () {
            mid = $(this).attr('mid');
            that = $(this);
            $.ajax({
                url:"/msg/clear",
                type: 'post',
                data:{'mid':mid},
                dataType: 'json',
                success: function (data) {
                    if(data.error ==1){
                        layer.msg(data.info, function(){
                        });
                    }else if(data.error ==0){
                        that.parent().parent().remove()
                    }
                },
                fail: function (err) {
                    console.log(err)
                }
            })

        })
        $('#LAY_delallmsg').click(function () {
            that = $(this);
            $.ajax({
                url:"/user/clearAll",
                type: 'post',
                dataType: 'json',
                success: function (data) {
                    if(data.error ==1){
                        layer.msg(data.info, function(){
                        });
                    }else if(data.error ==0){
                        $('#LAY_minemsg').remove()
                    }
                },
                fail: function (err) {
                    console.log(err)
                }
            })

        })
    });
</script>
@endsection